class Solution {
public:
    int matchPlayersAndTrainers(vector<int>& players, vector<int>& trainers) {
        ranges::sort(players);
        ranges::sort(trainers);
    
        int m = players.size(), n = trainers.size();
        int count = 0;
        for(int i = 0, j = 0; i < m; ++i)
        {
            while(j < n && trainers[j] < players[i]) ++j;
            if(j == n) break;
            if(players[i] <= trainers[j]) {
                ++count;
                ++j;
            }
        }
        return count;
    }
};
